<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Hashtable"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ page import="projects.project" %>
<%@ page import="projects.task" %>
<%@ page import="userInteraction.readUserInformation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="proj" class="projects.project"></jsp:useBean>
<jsp:setProperty property="*" name="proj"/>
<jsp:useBean id="userId" class="userInteraction.readUserInformation"></jsp:useBean>
<jsp:setProperty property="*" name="userId"/>
<jsp:useBean id="task" class="projects.task"></jsp:useBean>
<jsp:setProperty property="*" name="task"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../General Info/css.css" />
<title>Dashboard</title>
</head>
<%
	if (session.getAttribute("loggedIn") == null) {
		response.sendRedirect("../User/index.jsp");
		}	
	readUserInformation user = new readUserInformation();
	project prj = new project();
	Hashtable<Integer, ArrayList<String>> generalProjectInfo = prj.queryProjectsByLoggedUser(user.readUserId(session.getAttribute("loggedIn").toString()));
	Hashtable<Integer, ArrayList<String>> activityStream = prj.getActivityStream(user.readUserId(session.getAttribute("loggedIn").toString()));
	
	task tsk = new task();
	Hashtable<Integer, ArrayList<String>> futureTasks = tsk.queryFutureTasks(user.readUserId(session.getAttribute("loggedIn").toString()));
%>
<body>
	<jsp:include page="../General Info/header.jsp"/>
	<div class="body">
	<div class = "dashboard" >
		
		<div class = "up">
			
			<div class = "projects">
			<div class = "projectsHeader">Projects</div>
			<table style="float: right">
				<th>
					<td class="projectTableHeader">Project Name</td>
					<td class="projectTableHeader">Percentage</td>
					<td class="projectTableHeader">Days Left</td>
					<td class="projectTableHeader">Status</td>
					<td class="projectTableHeader">Role</td>
				</th>
				<%
				Enumeration<Integer> prjKeysEnum = generalProjectInfo.keys();
				ArrayList<Integer> projectKeys = new ArrayList<Integer>();
				
				while(prjKeysEnum.hasMoreElements()){
					projectKeys.add(prjKeysEnum.nextElement());
				}
				int color = 0;
				for(Integer key : projectKeys) {
					color = color + 1;
					ArrayList<String> projectInfo = new ArrayList<String>();
					projectInfo = generalProjectInfo.get(key);
					prj.setProjectId(key);
					String x = "../Projects/projectDashboard.jsp?id=" + key;   /* link + projectId */  
				if(color %2 == 0){				
				%>
				<tr class="even">
					<td class="cell"><a href="<% out.println(x); %>"> <% out.println(projectInfo.get(0)); %></a></td>   
					<td class="cell"><% out.println(projectInfo.get(1)); %></td>
					<td class="cell"><% out.println(prj.projectCoplition()); %></td>
					<td class="cell"><% out.println(projectInfo.get(2)); %></td>
					<td class="cell"><% out.println(projectInfo.get(3)); %></td>
					<td class="cell"><% out.println(projectInfo.get(4)); %></td>
				</tr>	
				<% }
				else{
					%>
					<tr class="odd">
					<td class="cell"><a href="<% out.println(x); %>"> <% out.println(projectInfo.get(0)); %></a></td>   
					<td class="cell"><% out.println(projectInfo.get(1)); %></td>
					<td class="cell"><% out.println(prj.projectCoplition()); %></td>
					<td class="cell"><% out.println(projectInfo.get(2)); %></td>
					<td class="cell"><% out.println(projectInfo.get(3)); %></td>
					<td class="cell"><% out.println(projectInfo.get(4)); %></td>
				</tr>	
				<% }
				}%>
			</table>
				
			</div>
			
			<div class = "activity">
			<div class = "projectsHeader">Activity Stream</div>
			
			<table style="width: 100%;">
			<%for(int i=1; i<=15; i++){
				if(i%2==0){
					if(Integer.parseInt(activityStream.get(i).get(5)) == 1){
						String text = activityStream.get(i).get(1) + " has created a <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>new task</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2) ;
						out.println("<tr class='even'><td class='cell'>" + text + "</td></tr>");
					}
					else if(Integer.parseInt(activityStream.get(i).get(5)) == 2){
						String text = activityStream.get(i).get(1) + " commented <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>task " + activityStream.get(i).get(0) + "</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2);
						out.println("<tr class='even'><td class='cell'>" + text + "</td></tr>");
					}
					else if(Integer.parseInt(activityStream.get(i).get(5)) == 3){
						String text = activityStream.get(i).get(1) + " has changed <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>task " + activityStream.get(i).get(0) + "</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2);
						out.println("<tr class='even'><td class='cell'>" + text + "</td></tr>");
					}
				}
				else{
					if(Integer.parseInt(activityStream.get(i).get(5)) == 1){
						String text = activityStream.get(i).get(1) + " has created a <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>new task</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2) ;
						out.println("<tr class='odd'><td class='cell'>" + text + "</td></tr>");
					}
					else if(Integer.parseInt(activityStream.get(i).get(5)) == 2){
						String text = activityStream.get(i).get(1) + " commented <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>task " + activityStream.get(i).get(0) + "</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2);
						out.println("<tr class='odd'><td class='cell'>" + text + "</td></tr>");
					}
					else if(Integer.parseInt(activityStream.get(i).get(5)) == 3){
						String text = activityStream.get(i).get(1) + " has changed <a href='../Tasks/task.jsp?id=" + activityStream.get(i).get(0) + "'>task " + activityStream.get(i).get(0) + "</a> for project <a href='../Projects/projectDashboard.jsp?id=" + activityStream.get(i).get(4) + "'>" + activityStream.get(i).get(3) + "</a> on " + activityStream.get(i).get(2);
						out.println("<tr class='odd'><td class='cell'>" + text + "</td></tr>");
					}
				}
				
				
			}
			%>
			</table>
			</div>
			
		</div>
		
		<div class = "down">
			
			<div class = "upcomingActivities">
			<div class = "projectsHeader">Upcoming Activities</div>
				<table style="float: right">
				<th>
					<!-- <td></td> -->
					<td class="projectTableHeader">Task Number</td>
					<td class="projectTableHeader">Task Name</td>
					<td class="projectTableHeader">Project Code</td>
					<td class="projectTableHeader">Days till deadline:</td>
				</th>
				<%
				Enumeration<Integer> taskKeysEnum = futureTasks.keys();
				ArrayList<Integer> taskKeys = new ArrayList<Integer>();
				while(taskKeysEnum.hasMoreElements()){
					taskKeys.add(taskKeysEnum.nextElement());
				}
				int colorTable = 0;
				for(Integer key : taskKeys) {
					colorTable = colorTable + 1;
					ArrayList<String> futureTsk = new ArrayList<String>();
					futureTsk = futureTasks.get(key);
					tsk.setTaskId(key);
					String taskPageLink = "../Tasks/task.jsp?id=" + key;   /* link + taskId */  
				if(colorTable%2 == 0){
				%>
				<tr class="even">
					<td class="cell"></td>
					<td class="cell"><a href="<% out.println(taskPageLink); %>"> <% out.println(key); %></a></td>   
					<td class="cell"><% out.println(futureTsk.get(0)); %></td>
					<td class="cell"><% out.println(futureTsk.get(1)); %></td>
					<td class="cell"><% out.println(futureTsk.get(2)); %></td>
				</tr>	
				<% }
				else{
					%>
					<tr class="odd">
					<td class="cell"></td>
					<td class="cell"><a href="<% out.println(taskPageLink); %>"> <% out.println(key); %></a></td>   
					<td class="cell"><% out.println(futureTsk.get(0)); %></td>
					<td class="cell"><% out.println(futureTsk.get(1)); %></td>
					<td class="cell"><% out.println(futureTsk.get(2)); %></td>
				</tr>	
				<%}
				}%>
			</table>
			
			</div>
			
			<div class = "charts">
			</div>
			
		</div>
	
	</div>
	<div class="push"></div>
	</div>
	<jsp:include page="../General Info/footer.jsp"/>
</body>
</html>